package com.web;

import com.domain.EmpChargeActivity;
import com.domain.Employee;
import com.service.employeeService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
/**
 * 员工看所有的活动
 * 接收 employeewrite.jsp 页面的employeePhone、employeePassword数据
 * 提交到 employeeService 的 findEmployeeName 函数查询员工的信息，
 * 提交到 employeeService 的 findEmployeeName 函数查询员工的职责数据
 * 转发到 employeeShow.jsp 页面进行展示
 */
@WebServlet("/findEmployee")
public class findEmployeeServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //1.解决中文乱码问题
        request.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset:UTF-8");

        //2.接收参数
        String employeePhone = request.getParameter("employeePhone");
        String employeePassword = request.getParameter("employeePassword");

        //3.进行获取
        //3.1查询员工的list数据
        employeeService empService = new employeeService();
        List<Employee> employeeNameList = empService.findEmployeeName(employeePhone,employeePassword);
        //3.2查询了员工的Employee对象数据
        Employee employee = empService.login(employeePhone, employeePassword);
        System.out.println(employee.getEmployeeName()+"员工查询了个人数据");
        //3.3查询了员工的EmpChargeActivity对象职责数据
        List<EmpChargeActivity> ECAList = new employeeService().FindECA(employee.getEmployeeId());
        System.out.println("查询员工"+employee.getEmployeeName()+"的职责数据");
        //System.out.println("ECAList = " + ECAList.toString());

        //4.进行存储
        request.setAttribute("employeeList",employeeNameList);
        request.setAttribute("ECAList",ECAList);
        //5.转发到页面进行展示
        request.getRequestDispatcher("/employeeShow.jsp").forward(request,response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }
}
